package com.example.websocketdemo.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/job")
public class JobAccountingController {

    @GetMapping("/message")
    public void j(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
//        JSONObject jsonObject = new JSONObject();
//        JSONObject json = new JSONObject();
//        JSONObject xinxi = new JSONObject();
//        JSONObject xinxi1 = new JSONObject();
//        JSONObject xinxi2 = new JSONObject();
//
//        JSONArray Array = new JSONArray();
//        jsonObject.put("instruction","updatepoi");
//        json.put("updatetype","reset");
//        json.put("poigroup","job");
//        json.put("poitype","job");
//
//        xinxi.put("活动编号","YX-JHA-002");
//        xinxi.put("活动名称","一号库区船舶卸油至储罐作业");
//        xinxi.put("活动频率","频繁进行");
//        xinxi.put("是否特殊作业","否");
//        xinxi.put("作业人员数量","3");
//        xinxi.put("岗位/地点","计量员");
//        xinxi.put("实施单位","运行部");
//        xinxi.put("作业区域","一号库区汽柴油罐区");
//
//        xinxi1.put("活动编号","YX-JHA-003");
//        xinxi1.put("活动名称","一号库区汽柴油装车作业");
//        xinxi1.put("活动频率","频繁进行");
//        xinxi1.put("是否特殊作业","否");
//        xinxi1.put("作业人员数量","5");
//        xinxi1.put("岗位/地点","运行部一号库区");
//        xinxi1.put("实施单位","运行部");
//        xinxi1.put("作业区域","汽柴油装车站");
//
//        xinxi2.put("活动编号","YX-JHA-005");
//        xinxi2.put("活动名称","清罐作业");
//        xinxi2.put("活动频率","频繁进行");
//        xinxi2.put("是否特殊作业","否");
//        xinxi2.put("作业人员数量","10");
//        xinxi2.put("岗位/地点","运行部一号库区");
//        xinxi2.put("实施单位","运行部");
//        xinxi2.put("作业区域","一号库区汽柴油罐区");
//
//
//        Array.add(xinxi);
//        Array.add(xinxi1);
//        Array.add(xinxi2);
//        json.put("Array",Array);
//        jsonObject.put("param",json);
//        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction","resetpoi");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");

        JSONObject jsonObject2 = new JSONObject();
        JSONObject json2 = new JSONObject();
        jsonObject2.put("instruction","showpoi");
        json2.put("showtype","group");
        json2.put("poigroup","job");
        json2.put("poitype","job");
        jsonObject2.put("param",json2);
        WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
//        for (int i = 0; i < 2; i++) {
//            if (i == 0) {
//                WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
//            } else {
//                WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
//            }
//        }
    }
}
